﻿using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 小组赛比分
    /// </summary>
    public class GameGroupVersusScoreAddDto : IValidatableObject
    {
        /// <summary>
        /// 小组对阵ID
        /// </summary>
        [Required]
        public Guid GroupVersusId { get; set; }

        /// <summary>
        /// 左边队伍得分
        /// </summary>
        [Required(ErrorMessage = "左边队伍得分必填")]
        public int Team1Score { get; set; }

        /// <summary>
        /// 左边队伍附加比分
        /// </summary>
        public int? Team1ExtraScore { get; set; }

        /// <summary>
        /// 右边队伍得分
        /// </summary>
        [Required(ErrorMessage = "右边队伍得分必填")]
        public int Team2Score { get; set; }

        /// <summary>
        /// 右边队伍附加比分
        /// </summary>
        public int? Team2ExtraScore { get; set; }

        /// <summary>
        /// 左边队伍总得分
        /// </summary>
        [JsonIgnore]
        public int OldTeam1Score { get; set; }

        /// <summary>
        /// 右边队伍总得分
        /// </summary>
        [JsonIgnore]
        public int OldTeam2Score { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Team1Score < 0 || Team2Score < 0 || Team1ExtraScore.GetValueOrDefault() < 0 || Team2ExtraScore.GetValueOrDefault() < 0)
            {
                yield return new ValidationResult("得分小于0");
                yield break;
            }

            if (Team1Score == 0 && Team2Score == 0)
            {
                yield return new ValidationResult("得分为0");
                yield break;
            }

            if (Team1Score + Team1ExtraScore.GetValueOrDefault() == Team2Score + Team2ExtraScore.GetValueOrDefault())
            {
                yield return new ValidationResult("两队比分相同");
                yield break;
            }
        }
    }
}
